/*     */ package org.apache.ftpserver.command.impl;
/*     */ 
/*     */ import java.io.IOException;
/*     */ import org.apache.ftpserver.command.AbstractCommand;
/*     */ import org.apache.ftpserver.ftplet.FtpException;
/*     */ import org.apache.ftpserver.ftplet.FtpFile;
/*     */ import org.apache.ftpserver.ftplet.FtpRequest;
/*     */ import org.apache.ftpserver.impl.FtpIoSession;
/*     */ import org.apache.ftpserver.impl.FtpServerContext;
/*     */ import org.apache.ftpserver.impl.LocalizedFtpReply;
/*     */ import org.apache.ftpserver.impl.ServerFtpStatistics;
/*     */ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class DELE
/*     */   extends AbstractCommand
/*     */ {
/*  48 */   private final Logger LOG = LoggerFactory.getLogger(DELE.class);
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public void execute(FtpIoSession session, FtpServerContext context, FtpRequest request)
/*     */     throws IOException, FtpException
/*     */   {
/*  58 */     session.resetState();
/*     */     
/*     */ 
/*  61 */     String fileName = request.getArgument();
/*  62 */     if (fileName == null) {
/*  63 */       session.write(LocalizedFtpReply.translate(session, request, context, 501, "DELE", null));
/*     */       
/*     */ 
/*  66 */       return;
/*     */     }
/*     */     
/*     */ 
/*  70 */     FtpFile file = null;
/*     */     try
/*     */     {
/*  73 */       file = session.getFileSystemView().getFile(fileName);
/*     */     } catch (Exception ex) {
/*  75 */       LOG.debug("Could not get file " + fileName, ex);
/*     */     }
/*  77 */     if (file == null) {
/*  78 */       session.write(LocalizedFtpReply.translate(session, request, context, 550, "DELE.invalid", fileName));
/*     */       
/*     */ 
/*  81 */       return;
/*     */     }
/*     */     
/*     */ 
/*  85 */     fileName = file.getAbsolutePath();
/*     */     
/*  87 */     if (file.isDirectory()) {
/*  88 */       session.write(LocalizedFtpReply.translate(session, request, context, 550, "DELE.invalid", fileName));
/*     */       
/*     */ 
/*  91 */       return;
/*     */     }
/*     */     
/*  94 */     if (!file.isRemovable()) {
/*  95 */       session.write(LocalizedFtpReply.translate(session, request, context, 450, "DELE.permission", fileName));
/*     */       
/*     */ 
/*  98 */       return;
/*     */     }
/*     */     
/*     */ 
/* 102 */     if (file.delete()) {
/* 103 */       session.write(LocalizedFtpReply.translate(session, request, context, 250, "DELE", fileName));
/*     */       
/*     */ 
/*     */ 
/*     */ 
/* 108 */       String userName = session.getUser().getName();
/*     */       
/* 110 */       LOG.info("File delete : " + userName + " - " + fileName);
/*     */       
/*     */       String homeDirectory= session.getUser().getHomeDirectory();
/*     */       RemoteOperateFileNameCache.setRemoteDeleteFileFtpHomeDirectory(homeDirectory+fileName, homeDirectory);  
/* 113 */       ServerFtpStatistics ftpStat = (ServerFtpStatistics)context.getFtpStatistics();
/*     */       
/* 115 */       ftpStat.setDelete(session, file);
/*     */     } else {
/* 117 */       session.write(LocalizedFtpReply.translate(session, request, context, 450, "DELE", fileName));
/*     */     }
/*     */   }
/*     */ }
